<template>
  <view class="navbar" :style="{paddingTop: safeHeight+ 'px', backgroundColor: bgc }">
    <navigator v-if="isShowIcon" @click="onClickBack" class="back icon-left" hover-class="none">
      <uni-icons type="left" size="22"></uni-icons>
    </navigator>
    <view class="title" :style="{color: titleColor}">{{title}}</view>
    <view class="right-tip">
      <text v-if="isShowCheckAll" class="text print" @click="onCheckAll">全选</text>
      <text v-if="isShowPrint" class="text print" @click="print">打印</text>
      <text v-if="isShowOver" class="text overTrain" @click="onOverTrain">结束训练</text>
    </view>
  </view>
</template>

<script>
  export default {
    name: "navbar",
    props: {
      title: String,
      titleColor: {
        type: String,
        default: '#000'
      },
      isShowIcon: {
        type: Boolean,
        default: true
      },
      isShowPrint: {
        type: Boolean,
        default: false
      },
      isShowOver: {
        type: Boolean,
        default: false
      },
      showBackTitle: {
        type: String,
        default: ''
      },
      isShowCheckAll: {
        type: Boolean,
        default: false
      },
      isChangeColor: {
        type: String,
        default: '#fe7930',
      },
      bgc: {
        type: String,
        default: 'transparent',
      }
    },
    data() {
      return {
        safeHeight: 50,
      }
    },
    created() {
      this.safeHeight = uni.getSystemInfoSync().safeAreaInsets.top
      // console.log(this.safeHeight);
    },
    methods: {
      // 点击切换全选
      onCheckAll() {
        this.$emit('onCheckAll')
      },
      onClickBack() {
        if (this.showBackTitle) {
          uni.showModal({
            title: '温馨提示',
            content: this.showBackTitle,
            success(res) {
              // console.log(res);
              if (res.confirm) {
                uni.navigateBack()
              }
            }
          })
        } else {
          uni.navigateBack()
        }
      },
      print() {
        this.$emit('print')
      },
      onOverTrain() {
        uni.redirectTo({
          url: "/pages/switchPages/speech"
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  ::v-deep .uni-icons.uniui-left {
    font-size: 40rpx !important;
    color: white !important;
    // background-color: ;
  }

  .navbar {
    // position: relative;
    position: fixed;
    z-index: 999;
    left: 0;
    right: 0;
    // padding-top: 25rpx;
    padding-bottom: 20rpx;
    // background-color: cornflowerblue;

    .title {
      height: 60rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 36rpx;
      color: #000000;
      font-weight: 500;
    }

    .right-tip {
      position: absolute;
      right: 20rpx;
      top: 54%;
      transform: translateY(-50%);
      font-size: 22rpx;
      // font-weight: 600;
      // color: white;
      display: flex;
      align-items: center;
      height: 100%;

      .print {
        margin-right: 25rpx;
        // color: brown;
      }

      .overTrain {
        // color: darkcyan;
      }
    }

    .back {
      position: absolute;
      height: 40rpx;
      width: 40rpx;
      left: 20rpx;
      // top: 50%;
      // transform: translateY(-50%);
      bottom: 30rpx;

      display: flex;
      justify-content: center;
      align-items: center;
    }

  }
</style>
